package com.xyhy.starter.security.handler;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import com.xyhy.core.utils.web.ServletUtils;
import com.xyhy.core.web.model.wrapper.Result;
import com.xyhy.core.web.model.wrapper.ResultCode;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AccessDeniedHandlerImpl implements AccessDeniedHandler {

  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response,
                     AccessDeniedException accessDeniedException) throws IOException, ServletException {
    ServletUtils.responsePrint(response, Result.fail(ResultCode.FORBIDDEN, accessDeniedException));
  }

}
